import config from "../config";
import { useStorage } from "../hooks/useStorage";
const Storage = useStorage()
const {BASE_URL} = config
const upload = (params)=>{
	return new Promise((res,rej)=>{
		uni.chooseImage({
			success: (chooseImageRes) => {
				const tempFilePaths = chooseImageRes.tempFilePaths;
				uni.uploadFile({
					url: BASE_URL+params.url, //仅为示例，非真实的接口地址
					filePath: tempFilePaths[0],
					name: params.name?params.name:'file',
					formData: {
						...params.data
					},
					header:{Token:Storage.getCache("token")?Storage.getCache("token"):""},
					success: (uploadFileRes) => {
						res(uploadFileRes)
					}
				});
			}
		});
	})
}

export {upload}